package util;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.InputStream;

/**
 * @Author zhangrui
 * @Date 2018/10/30 11:05
 */
public class DataBaseTools {

    private static SqlSessionFactory _sessionLHFactory;

    //绿化DB
    static {
        try {
            InputStream inputStream = Resources.getResourceAsStream("SqlMapConfig.xml");
            //构建sqlSession的工厂
            _sessionLHFactory = new SqlSessionFactoryBuilder().build(inputStream);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * LandscapingDB绿化
     *
     * @return
     */
    public static SqlSession getLandscapingDBSession() {
        return _sessionLHFactory.openSession(true);
    }
}
